//
//  GQNavigationViewController.m
//  LotteryProject
//
//  Created by Ezra on 16/5/19.
//  Copyright © 2016年 Ezra. All rights reserved.
//

#import "GQNavigationViewController.h"

@interface GQNavigationViewController ()<UIGestureRecognizerDelegate>

@end

@implementation GQNavigationViewController

+(void)initialize
{
    UINavigationBar *bar = [UINavigationBar appearanceWhenContainedInInstancesOfClasses:@[self]];
    
    [bar setBackgroundImage:[UIImage imageNamed:@"NavBar64"] forBarMetrics:UIBarMetricsDefault];
    
    //设置字体颜色和大小
    NSMutableDictionary *dict = [NSMutableDictionary dictionary];
    dict[NSFontAttributeName] = [UIFont boldSystemFontOfSize:20];
    dict[NSForegroundColorAttributeName] = [UIColor whiteColor];
    
    [bar setTitleTextAttributes:dict];
    
    //设置navigationbar左按钮颜色并取消文字
    bar.tintColor = [UIColor whiteColor];
    UIBarButtonItem *item = [UIBarButtonItem appearanceWhenContainedInInstancesOfClasses:@[self]];
    
    //把字移出屏幕外面
    [item setBackButtonTitlePositionAdjustment:UIOffsetMake(0, -100) forBarMetrics:UIBarMetricsDefault];
    
    
}

- (void)viewDidLoad {
    [super viewDidLoad];

    //实现窗口滑动跳转
    self.interactivePopGestureRecognizer.enabled = NO;
    
    id target = self.interactivePopGestureRecognizer.delegate;
    
    UIPanGestureRecognizer *pan = [[UIPanGestureRecognizer alloc]initWithTarget:target action:@selector(handleNavigationTransition:)];
    
    [self.view addGestureRecognizer:pan];
    
    pan.delegate = self;
}

-(BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer
{
    //如果控制器数量大于1返回yes 可以滑动！
    return self.viewControllers.count > 1;
}

- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated
{
    [super pushViewController:viewController animated:animated];
    
    if (self.viewControllers.count > 1) {
        
        //注意这里是viewController隐藏不是self
        viewController.hidesBottomBarWhenPushed = YES;
        
    }
    
    
}
- (void)handleNavigationTransition:(id)sender{
    
}

@end
